// 登录模块
import { makeAutoObservable } from "mobx"
import { http, getToken, setToken, clearToken } from '@/utils'

class LoginStore {
  token = getToken() || ""
  constructor() {
    makeAutoObservable(this)
  }
  // 登录
  login = async ({ mobile, code }) => {
    await http.post('http://geek.itheima.net/v1_0/authorizations', {
      mobile,
      code
    }).then((res) => {
      const { token } = res.data
      setToken(token)
      this.token = token
    })
  }
  // 退出
  logout = () => {
    this.token = ''
    clearToken()
  }
}
export default LoginStore